﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassLibraryChat
{
    public class DBManipulation
    {
        private static ChatDBdbmlDataContext context = new ChatDBdbmlDataContext();

        public static Dictionary<string, int> GetAllChannels()
        {
            var channels = from channel in context.Channels
                           select channel;
            Dictionary<string, int> result = new Dictionary<string, int>();
            foreach (Channel channel in channels)
            {
                result.Add(channel.Name, channel.ChannelID);
            }
            return result;
        }

        public static Dictionary<string, int> GetAllUsers()
        {
            var users = from user in context.Users
                        select user;
            Dictionary<string, int> result = new Dictionary<string, int>();
            foreach (User user in users)
            {
                result.Add(user.Username, user.UserID);
            }
            return result;
        }

        public static List<Message> GetMessagesByChannel(string channel)
        {
            List<Message> result = (from message in context.Messages
                                    join chann in context.Channels on message.ChannelID equals chann.ChannelID
                                    where chann.Name == channel
                                    select message).ToList();
            return result;
        }
    }
}
